package com.woniu.cq.medical.service.impl;

//import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.woniu.cq.medical.controller.form.PrescriptionForm;
import com.woniu.cq.medical.controller.form.PrescriptionInfoForm;
import com.woniu.cq.medical.controller.form.ProjectForm;
import com.woniu.cq.medical.controller.form.RegisterAllForm;
import com.woniu.cq.medical.entity.Prescription;
import com.woniu.cq.medical.dao.PrescriptionMapper;
import com.woniu.cq.medical.service.PrescriptionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2020-09-08
 */
@Service
public class PrescriptionServiceImpl extends ServiceImpl<PrescriptionMapper, Prescription> implements PrescriptionService {

    @Autowired
    private PrescriptionMapper prescriptionMapper;

    /**
     * 新增一条处方
     * 返回自增长的主键值
     * @param prescriptionData
     */
    @Override
    public Integer insertPrescription(List<PrescriptionForm> prescriptionData) {
        Prescription prescription = new Prescription();
        //定义一个变量用于储存整个处方的总价
        double tol = 0;
        //定义一个变量用于接收患者ID
        Integer id = -1;
        //定义一个变量用于接收患者的临床诊断信息
        String clinicalDiagnosis = "";

        //计算所有处方的总价
        for (PrescriptionForm p : prescriptionData) {
            //将每个处方的总价累计相加，就是整个处方的总价
            tol+=p.getProductTotal();
            id=p.getPatientId();
            clinicalDiagnosis = p.getClinicalDiagnosis();
        }
        prescription.setTotal(tol);
        prescription.setPatientId(id);
        prescription.setClinicalDiagnosis(clinicalDiagnosis);
        prescription.setStatus("未支付");
        prescriptionMapper.insert(prescription);
        return prescription.getPrescriptionId();
    }

    /**
     * 查询处方详情，用于支付
     * @return
     */
    @Override
    public List<PrescriptionInfoForm> selectProduct(String patientIdCard) {
        List<PrescriptionInfoForm> prescriptionInfoForm = prescriptionMapper.selectProduct(patientIdCard);
        return prescriptionInfoForm;
    }

    @Override
    public List<ProjectForm> selectProject(String patientIdCard) {
        List<ProjectForm> projectForm = prescriptionMapper.selectProject(patientIdCard);
        return projectForm;
    }

    @Override
    public List<PrescriptionInfoForm> selectProductAll(String patientIdCard) {
        List<PrescriptionInfoForm> prescriptionInfoForm = prescriptionMapper.selectProductAll(patientIdCard);
        return prescriptionInfoForm;
    }

    @Override
    public List<ProjectForm> selectProjectAll(String patientIdCard) {
        List<ProjectForm> projectForm = prescriptionMapper.selectProjectAll(patientIdCard);
        return projectForm;
    }

    @Override
    public List<RegisterAllForm> selectRegister(String patientIdCard) {
        List<RegisterAllForm> registerAllForms = prescriptionMapper.selectRegister(patientIdCard);
        return registerAllForms;
    }
}
